<?php
/**
 * Created by PhpStorm.
 * User: Zhoujinda
 * Date: 2016/7/5
 * Time: 10:50
 */
namespace Webview\Controller;

use Admin\Api\DatatreeApi;
use Admin\Api\PostApi;
use Admin\Api\VPostInfoApi;
use Common\Controller\BaseController;
use Think\Controller;

class HelpController extends BaseController{
    public function index(){
        $this->assignTitle('帮助中心');

        //获取APP帮助中心分类
        $result  = apiCall(DatatreeApi::QUERY_NO_PAGING,array(array('parentid'=>C('datatree.HELP_APP_POST_CATEGORY'))));
        if($result['status']){
            $data = [];
            foreach($result['info'] as $val){
                $map = ['post_category'=>$val['id']];
                $result = apiCall(PostApi::QUERY_NO_PAGING,[$map,false,'id,post_title']);
                if(!$result['status']){
                    exit($result['info']);
                }
                $data[] = [
                    'cate_name' => $val['name'],
                    'list' => !is_null($result['info'])?$result['info']:[]
                ];
            }
            $this->assign('help',$data);

        }else{
            exit($result['info']);
        }

        $this->display();
    }

    public function detail(){
        $this->assignTitle('详情');
        $id = I('id');

        $map = ['id'=>$id];
        $result = apiCall(VPostInfoApi::GET_INFO,[$map]);
        if($result['status']){
            $this->assign('post_title',$result['info']['post_title']);
            $this->assign('post_content',htmlspecialchars_decode($result['info']['post_content']));
        }else{
            exit($result['info']);
        }
        $this->display();
    }
}